/**
 *
 * Created by kouzhenfnag, 1/9/2011 23:19:40
 *
 */

function  validateVideoUrl(ori_url) 
{
	var strArray = new Array(); 
	strArray = ori_url.split('/'); 
	var vid = strArray[strArray.length-1];
	if (vid == null) {
		// Not Found
	  	return 'NotFoundVideo';
	}
	var dst_url = 'http://v.ku6.com/fetchVideo4Player/' + vid;

	var json_str = download_page(dst_url);
	var json = eval('(' + json_str + ')');
	
	var data = json.data;
	var sb = [];
	var files = data.f;
	var fArray = new Array(); 
	fArray = files.split(",");
	for(var i = 0; i < fArray.length; i++){
		sb.push(fArray[i]);
	}
	
    if(sb.length>0){
    	var html = download_page(ori_url,'GBK');
		//var matches = html.match(/<title>(.*?)<\/title>/);
		var matches = html.match(/<title>([\s\S]*?)<\/title>/);
		var duration = data.vtime;
	    if(matches){
	 	   return 'success_title:' + encodeURIComponent(matches[1])
	 	          + '\n video_urls:' + encodeURIComponent(sb)
	 	          + '\n seconds:' + Math.round(parseInt(duration));
	    }
    }
    return 'error:empty_path';
}

//http://v.ku6.com/show/wDRxSSruvEc6_oTH.html
function js_get_media_url(ori_url) 
{
	var strArray = new Array(); 
	strArray = ori_url.split("/"); 
	var vid = strArray[strArray.length-1];

	if (vid == null) {
		// vid not found
		return '';
	}
	var dst_url = 'http://v.ku6.com/fetchVideo4Player/' + vid;

	var json_str = download_page(dst_url);
	var json = eval('(' + json_str + ')');
	
	var data = json.data;
	var sb = [];
	var files = data.f;
	var fArray = new Array(); 
	fArray = files.split(",");
	for(var i = 0; i < fArray.length; i++){
		sb.push(fArray[i]);
	}

	return sb;
}
